<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name=" apple-mobile-web-app-capable" />
    <!-- 隐藏状态栏  -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <!-- <title>绑定手机号码</title> -->
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/details.css">
</head>

<body>
    <header>
        <div class="wrapper clearfix">
            <div class="login_fl fl">
                <a href="javascript:history.back()" class="login_icon"><img src="img/srh_icon.png" alt=""></a>
            </div>
            <h1>绑定手机号码</h1>
        </div>
    </header>
    <article class="mod-forgot p10 login_mod">
        <input type="text" class="phone" placeholder="输入新的号码" value="" id="phoneNum">
        <input type="text" class="vcode" placeholder="验证码" id="captcha">
        <a class="gain_vcode gain_vcode1" href="javascript:void(0)" id="captchaBtn">获取</a>
        <input type="submit" class="next_step" value="确认修改" onclick="toNextPage()">
    </article>
</body>
<script src="js/jquery-1.11.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/constants.js"></script>
<script src="js/common.js"></script>
<script>
var userInfo = base64TojsonObj(getParameterByName('userInfo'));
// 提交
var urlSubmit = server_host + '/userweb/update/resetNewPhoneNum.do?';

var regex = /^1[3|4|5|8|7][0-9]\d{4,8}$/;

var captchaBtn = $('#captchaBtn');

var remainTime = 60;

// var newphone = $('#phone').val();
var phoneNum;

/*******************************验证码获取****************************/
function captchaClick() {
    phoneNum = $('#phoneNum').val();
    // 获取验证码
    var urlCaptcha = server_host + '/userweb/update/sendSmsToUserResetNewPhoneNum.do?phoneNum=' + phoneNum;

    if (regex.test(phoneNum)) {
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: urlCaptcha,
            success: function(data) {
                console.log(data.data);
                if (data.data.code == 0) {
                    captchaBtn.addClass('act');
                    captchaBtn.unbind('click');
                    captchaBtn.html(remainTime);
                    var timer = setInterval(function() {
                        remainTime--;
                        captchaBtn.html(remainTime);
                        if (remainTime == 0) {
                            clearInterval(timer);
                            captchaBtn.removeClass('act');
                            captchaBtn.bind('click', captchaClick);
                            captchaBtn.html('获取');
                            remainTime = 60;
                        }
                    }, 1000);
                } else {
                    alert(data.data.msg);
                }
            }
        });
    } else {
        alert('请输入正确的手机号码！');
    }
}

$(document).ready(function() {
    captchaBtn.bind('click', captchaClick);
});

/*******************************确认修改手机号****************************/
function toNextPage() {
    phoneNum = $('#phoneNum').val();
    var vNum = $('#captcha').val()

    if (captchaBtn == '') {
        alert('请输入验证码');
    } else {
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: urlSubmit + '&phoneNum=' + phoneNum + '&vNum=' + vNum,

            success: function(data) {
                console.log(data.data);
                if (data.data.isSuccess) {
                    alert(data.data.msg);
                    // 跳到注册页
                    location.href = 'login.html';
                } else {
                    alert(data.data.msg);
                }
            }
        });
    }
}
</script>
<script>
    _maq.push(['_setMaq', 're_phonenum']);
</script>
</html>
